package org.adream.account.rest.api;

import org.adream.account.entity.HrmResourceEntity;
import org.adream.account.model.ResultModel;
import org.adream.account.rest.api.model.HrmResourceSearchForm;
import org.adream.account.service.HrmResourceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;

/**
 * oa api
 * @author sl
 *
 */
@RequestMapping("/hrmResource/")
@Controller
public class HrmResourceApiController {
	
	@Autowired
	private HrmResourceService hrmResourceService;
	
	private final static Logger logger = LoggerFactory.getLogger(HrmResourceApiController.class);
	
	/**
	 * 分页查询
	 * @return
	 */
	@RequestMapping(value = "/queryPageBoundHrmResources", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
	@ResponseBody
	public ResultModel<PageInfo<HrmResourceEntity>> queryPageBoundHrmResources(@RequestBody(required = false) HrmResourceSearchForm form) {
		if(form == null) {
			logger.warn("查询失败,form参数为空:(");
			return new ResultModel<PageInfo<HrmResourceEntity>>(ResultModel.ERR_PARAM, "查询失败,请求参数有误", null);
		}
		PageInfo<HrmResourceEntity> page = hrmResourceService.queryBoundHrmResources(form.getLoginid(),form.getPageNo(),form.getPageSize());
		return new ResultModel<PageInfo<HrmResourceEntity>>(ResultModel.SUCCESS, ResultModel.SUCCESS_MSG, page);
	}
	
	/**
	 * 解绑已绑定的OA账号
	 */
	@RequestMapping(value = "/unBindOaAccount", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
	@ResponseBody
	public ResultModel<String> unBindOaAccount(Integer id) {
		if(id == null) {
			logger.warn("解绑oa账号失败,id为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "查询失败,请求参数有误", null);
		}
		return hrmResourceService.unBindOaAccount(id);
	}
}